<?php

namespace App\Admin\Controllers;

use App\Services\CompanyService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 公司管理
 *
 * @property CompanyService $service
 */
class CompanyController extends AdminController
{
	protected string $serviceName = CompanyService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('company_name', '公司名称'),
				amis()->TableColumn('email', '发件邮箱'),
				amis()->SwitchControl('is_enabled', '启用状态')->options([
					'0' => '禁用',
					'1' => '启用'
				]),
				amis()->TableColumn('password', '发件密码'),
				amis()->TableColumn('smtp_server', 'SMTP服务器地址'),
				amis()->TableColumn('template', '割接模版内容'),
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				amis()->TableColumn('updated_at', admin_trans('admin.updated_at'))->type('datetime')->sortable(),
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('company_name', '公司名称'),
			amis()->TextControl('email', '发件邮箱'),
			amis()->SwitchControl('is_enabled', '启用状态')->options([
				'0' => '禁用',
				'1' => '启用'
			]),
			amis()->TextControl('password', '发件密码'),
			amis()->TextControl('smtp_server', 'SMTP服务器地址'),
			amis()->TextareaControl('template', '割接模版内容'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('company_name', '公司名称')->static(),
			amis()->TextControl('email', '发件邮箱')->static(),
			amis()->TextControl('is_enabled', '启用状态: 0-禁用 1-启用')->static(),
			amis()->TextControl('password', '发件密码')->static(),
			amis()->TextControl('smtp_server', 'SMTP服务器地址')->static(),
			amis()->TextControl('template', '割接模版内容')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}